<template>
	<div id="sys_params">
		<main-head></main-head>

		<main-content>
			<el-form :inline="true" :model="params" class="demo-form-inline">
				<el-form-item label="创建日期">
					<el-date-picker v-model="date" type="datetimerange" range-separator="至" start-placeholder="开始日期"
						end-placeholder="结束日期" @change="dateSearch()">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="">
					<el-input v-model="params.id" placeholder="请输入商家id" clearable></el-input>
				</el-form-item>
				<el-form-item label="">
					<el-input v-model="params.name" placeholder="输入商家名称模糊搜索" clearable></el-input>
				</el-form-item>
				<el-button type="primary" @click="search()"><i class="iconfont iconsousuo"></i>搜索</el-button>
			</el-form>
			<el-table :data="list" stripe style="width: 100%" v-loading="load">
				<el-table-column prop="id" label="id" align="center"></el-table-column>
				<el-table-column prop="account" label="账号" align="center">
				</el-table-column>
				<el-table-column prop="usId" label="用户id" align="center">
				</el-table-column>
				<el-table-column prop="phone" label="联系方式" align="center">
				</el-table-column>
				<el-table-column prop="name" label="姓名" align="center">
				</el-table-column>
				<el-table-column prop="status" label="状态" align="center">
					<template slot-scope="scope">
						<span>{{ scope.row.status == 0 ? "正常" : "已冻结" }}</span>
					</template>
				</el-table-column>
				<el-table-column label="创建时间" align="center">
					<template slot-scope="scope">
						<span>{{
              $moment(scope.row.createTime).format("Y-MM-DD HH:mm")
            }}</span>
					</template>
				</el-table-column>
				<el-table-column label="操作" align="center" width="300">
					<template slot-scope="scope">
						<el-button type="danger" size="mini" @click="update(scope.row.id)" v-if="scope.row.status == 0">
							<i class="iconfont iconlianxi2hebing-19"></i>冻结
						</el-button>
						<el-button type="primary" size="mini" @click="update(scope.row.id)" v-else><i
								class="iconfont iconkaisuohuansuo"></i>解冻</el-button>
						<el-button type="success" size="mini" @click="$router.push('/merchant/vegetablePlot?id='+scope.row.id)">
							<i class="iconfont iconbaohugengdiyuyongjiujibennongtian"></i>拥有的土地区域
						</el-button>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination class="page" background :layout="
          $store.state.isPhone
            ? 'total, prev, pager, next'
            : 'total, sizes, prev, pager, next, jumper'
        " :current-page.sync="params.pageNo" :page-size.sync="params.pageSize" :total="total" @size-change="search"
				@current-change="getList">
			</el-pagination>
		</main-content>
	</div>
</template>

<script>
	let checkOptions = [];
	export default {
		data() {
			return {
				//表单Label宽度
				labelWidth: "100px",
				form: {},
				dialog: false,
				date: "",
				list: [],
				load: false,
				params: {
					name: "",
					pageSize: 10,
					pageNo: 1,
					isCount: true,
					startTime: "",
					endTime: "",
					id: "",
				},
				total: 0,
			};
		},

		mounted() {
			this.search();
		},

		methods: {
			upload() {
				this.form.time = new Date(this.form.birthday).getTime()
				delete(this.form.birthday)
				delete(this.form.createTime)
				delete(this.form.loginTime)
				this.$confirm('确认修改用户信息吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					console.log(this.form)
					this.$request.post({
						url: "admin/adUsInfo/updateInfo",
						params: this.form,
						success: (result) => {
							this.$message.success(result);
							this.dialog = false;
							this.getList()
						},
						finally: () => {
							this.load = false;
						},
					});
				})
			},
			search() {
				this.params.pageNo = 1;
				this.params.isCount = true;
				this.getList();
			},

			getList() {
				this.load = true;
				this.$request.post({
					url: "admin/merchantManage/merchantList",
					params: this.params,
					success: (result) => {
						if (this.params.isCount) {
							this.total = result.total;
						}
						this.params.isCount = false;
						this.list = result.list;
					},
					finally: () => {
						this.load = false;
					},
				});
			},

			//时间改变
			dateSearch() {
				if (this.date != null) {
					this.params.startTime = this.$moment(this.date[0]).format(
						"Y-MM-DD " + "23:59:59"
					);
					this.params.endTime = this.$moment(this.date[1]).format(
						"Y-MM-DD " + "23:59:59"
					);
				} else {
					this.params.startTime = ""
					this.params.endTime = ""
				}
				this.search();
			},
			//修改状态
			update(id) {
				this.$request.post({
					url: "admin/merchantManage/updateStatus",
					params: {
						id
					},
					success: (result) => {
						this.$message.success(result);
						this.search();
					},
				});
			},
			cleanDialog() {
				this.form = {};
			},
			openDialog(row) {
				this.cleanDialog();
				this.dialog = true;
				//浅拷贝				
				this.form = JSON.parse(JSON.stringify(row));
			},
		},
	};
</script>

<style>
</style>

<style scoped>
	.page {
		text-align: right;
		margin-top: 20px;
	}

	.iconfont {
		font-size: 10px;
		margin-right: 3px;
	}
</style>
